package com.anycc.cloud.gateway.filter;

import com.netflix.zuul.context.RequestContext;
import org.springframework.stereotype.Component;

/**
 * Created by DELL on 2019/1/30.
 */
@Component
public class FilterUtils {
    public static final String PASSWORD = "password";
    public static final String PRE_FILTER_TYPE = "pre";
    public static final String POST_FILTER_TYPE = "post";
    public static final String ROUTE_FILTER_TYPE = "route";
    public static final String JWT = "jwt";

    public String getJwt() {
        RequestContext ctx = RequestContext.getCurrentContext();

        if (ctx.getRequest().getHeader(JWT) != null) {
            return ctx.getRequest().getHeader(JWT);
        } else {
            return ctx.getZuulRequestHeaders().get(JWT);
        }
    }

    public void setJWT(String jwt){
        RequestContext ctx = RequestContext.getCurrentContext();
        ctx.addZuulRequestHeader(JWT, jwt);
    }
}
